package com.hhkj.admin.conf.controller;

import com.hhkj.admin.conf.common.cont.ConfConst;
import com.hhkj.admin.conf.domain.Conf;
import com.hhkj.admin.conf.model.extend.WithdrawalLimit;
import com.hhkj.admin.conf.model.req.CommissionRateReq;
import com.hhkj.admin.conf.model.req.ConfReq;
import com.hhkj.admin.conf.model.req.ReceivingAccountReq;
import com.hhkj.admin.conf.model.req.WithdrawalLimitReq;
import com.hhkj.admin.conf.model.res.CommissionRateRes;
import com.hhkj.admin.conf.model.res.ConfRes;
import com.hhkj.admin.conf.model.res.ReceivingAccountRes;
import com.hhkj.admin.conf.model.res.WithdrawalLimitRes;
import com.hhkj.admin.conf.service.biz.CommissionRateBizService;
import com.hhkj.admin.conf.service.biz.ConfBizService;
import com.hhkj.admin.conf.service.biz.ReceivingAccountBizService;
import com.hhkj.admin.conf.service.biz.WithdrawalLimitBizService;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.v2.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.valid.VAdd;
import com.ruoyi.common.valid.VEdit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/conf")
@PermissionPrefix(value = PermissionPrefix.NO_PERMISSION)
public class ConfController extends BaseController<Conf, ConfReq, ConfRes, ConfBizService> {

    @Autowired
    private CommissionRateBizService commissionRateBizService;

    /**
     * 查看佣金返利规则
     * @return
     */
    @GetMapping("/commission/rate")
    public AjaxResult getCommissionRate() {
        CommissionRateRes res = getBizService().getConf(ConfConst.Code.COMMISSION_RATE);
        return success(res);
    }

    /**
     * 更新佣金返利规则
     * @param commissionRateReq 新的佣金返利规则
     * @return
     */
    @PutMapping("/commission/rate")
    public AjaxResult updateCommissionRate(@RequestBody @Validated(value = VEdit.class) CommissionRateReq commissionRateReq) {
        return success(getBizService().updateConf(commissionRateReq, ConfConst.Code.COMMISSION_RATE));
    }

    /**
     * 删除待生效佣金返利规则
     * @return
     */
    @DeleteMapping("/commission/rate")
    public AjaxResult removeCommissionRate() {
        return success(commissionRateBizService.removeCommissionRate());
    }

    /**
     * 查看提现规则
     * @return
     */
    @GetMapping("/withdrawal/limit")
    public AjaxResult getWithdrawalLimit() {
        WithdrawalLimitRes res = getBizService().getConf(ConfConst.Code.WITHDRAWAL_LIMIT);
        return success(res);
    }

    /**
     * 修改提现规则
     * @param withdrawalLimitReq 新的规则
     * @return
     */
    @PutMapping("/withdrawal/limit")
    public AjaxResult updateWithdrawalLimit(@RequestBody WithdrawalLimitReq withdrawalLimitReq) {
        return success(getBizService().updateConf(withdrawalLimitReq, ConfConst.Code.WITHDRAWAL_LIMIT));
    }

    /**
     * 查看收款账户
     * @return
     */
    @GetMapping("/receiving/account")
    public AjaxResult getReceivingAccount() {
        ReceivingAccountRes res = getBizService().getConf(ConfConst.Code.RECEIVING_ACCOUNT);
        return success(res);
    }

    /**
     * 修改收款账户
     * @param receivingAccountReq 新的收款账户
     * @return
     */
    @PutMapping("/receiving/account")
    public AjaxResult updateReceivingAccount(@RequestBody ReceivingAccountReq receivingAccountReq) {
        return success(getBizService().updateConf(receivingAccountReq, ConfConst.Code.RECEIVING_ACCOUNT));
    }

    /**
     * 获取所有规则
     * @return
     */
    @GetMapping("/all")
    public AjaxResult all() {
        return success(getBizService().all());
    }
}
